home *** CD-ROM | disk | FTP | other *** search
- #include <stl.h>
-
- // The macString class stores a string and is accesible either as a Pascal string or as a c-string.
- // The data is stored in str, a vector<char> and also in parallel in a Pascal string.
- // Bugs:
- // Should issue warnings when a macString with over 255 characters is accessed as a unsigned char *.
- // as this could result is truncation and data loss.
- class macString{
- public:
- macString() : bPStrOK(true), bCStrOK(true), s(256) {}
- macString(const macString&);
- macString(char c) : bPStrOK(false), bCStrOK(true), s(256) {s[0] = c; synchronize();}
- macString(const char *s);
- macString(const unsigned char *s);
-
- operator char *() {return str();}
- operator const char *() {return conststr();}
- operator unsigned char *() {return pstr();}
- operator const unsigned char *() {return constpstr();}
- friend ostream& operator<< (ostream& os, macString& ms) {os << ms.conststr(); return os;}
- friend ostream& operator<< (ostream& os, const macString& ms) {os << ms.conststr(); return os;}
- friend operator< (macString& ms1, macString& ms2) {return strcmp(ms1.conststr(), ms2.conststr()) < 0;}
- friend operator< (const macString& ms1, const macString& ms2) {return strcmp(ms1.conststr(), ms2.conststr()) < 0;}
- friend operator== (macString& ms1, macString& ms2) {return !strcmp(ms1.conststr(), ms2.conststr());}
- friend operator== (const macString& ms1, const macString& ms2) {return !strcmp(ms1.conststr(), ms2.conststr());}
- macString& operator+=(const macString &);
- friend macString operator+ (macString& ms0, macString& ms1);
- macString& operator= (const macString&);
- void dump(void);
- private:
- bool bCStrOK;
- bool bPStrOK;
- vector<char> s;
- Str255 str255;
- const char* conststr() const;
- char* str();
- const unsigned char* constpstr();
- unsigned char* pstr() {synchronize(); bCStrOK = false; return str255;}
- void synchronize();
- };
-